package com.one.oa.api.filter;

import com.one.oa.api.service.ApiLogService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


@Component
@WebFilter("/*")
public class ApiRequestFilter implements Filter {
    @Resource
    private ApiLogService service;
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        String url=request.getRequestURI();
        if(url.contains("/api/") && !url.contains("/api/apilog/page.do")){
            String ip=request.getRemoteAddr();
//            if(!ip.equals("0:0:0:0:0:0:0:1")){
//                //接口
//                service.save(ip,url);
//            }
            service.save(ip,url);
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
